import { MutationTree } from 'vuex'
interface AppState {
  // language: 'zh_cn' | 'en'
  theme: 'light' | 'dark'
}
export const state = () => {
  return {
    // language: 'zh_cn',
    theme: 'light',
  } as AppState
}

export type RootState = ReturnType<typeof state>


export const mutations: MutationTree<RootState> = {
  SET_STATE(state, newState: AppState) {
    for (const key in newState) {
        if (Object.prototype.hasOwnProperty.call(newState, key)) {
            // @ts-ignore
            state[key] = newState[key]
        }
    }
    // @ts-ignore
    this.$cookies.set('_store/app', state)
 },

  // 设置theme
  SET_THEME(state, theme: AppState['theme']) {
    state.theme = theme
    // @ts-ignore
    this.$cookies.set('_store/app', state)
  },

  // 设置language
  // SET_LANGUAGE(state, language: AppState['language']) {
  //   state.language = language
  //   // @ts-ignore
  //   this.$cookies.set('_store/app', state)
  // },
}

